﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ZK.Common;
using ZK.YCGLRD_TransManage.Models;

namespace ZK.YCGLRD_TransManage.Com
{
    public partial class WebApiService
    {
        private static readonly string LoginCN = "login/";
        private static readonly string LoginAN = LoginCN + "login";//登录

        private static readonly string CsCN = "cs/";
        private static readonly string GetHardWareSAN = CsCN + "getHardWareS";//设备监控列表查询
        private static readonly string AddHardWareAN = CsCN + "addHardWare";//设备监控新增接口
        private static readonly string UpdateHardWareByidAN = CsCN + "updateHardWareByid";//设备监控列修改接口
        private static readonly string GetHardWareByIdAN = CsCN + "getHardWareById";//设备监控详情
        private static readonly string DelHardWareByIdAN = CsCN + "delHardWareById";//设备删除接口
        private static readonly string GetBlackAN = CsCN + "getBlack";//当前车辆是否为黑名单
        private static readonly string UpdateHardWareByNameAN = CsCN + "updateHardWareByName";//根据硬件名称修改硬件状态

        private static readonly string AutoControlTransportCN = "autoControlTransport/";
        private static readonly string GetTheLatestAN = AutoControlTransportCN + "getTheLatest";//获取最后磅单信息接口
        private static readonly string GetTruckYxInfoAN = AutoControlTransportCN + "getTruckYxInfo";//获取磅单信息接口
        private static readonly string TruckAdmissionAN = AutoControlTransportCN + "truckAdmission";//车辆入场接口
        private static readonly string TruckExitAN = AutoControlTransportCN + "truckExit";//车辆出场接口  
        private static readonly string TruckTareAN = AutoControlTransportCN + "truckTare";//车辆除皮接口
        private static readonly string TruckUnloadingAN = AutoControlTransportCN + "truckUnloading";//车辆卸车接口
        private static readonly string TruckWeighAN = AutoControlTransportCN + "truckWeigh";//车辆称重接口
        private static readonly string TruckWeightBillAN = AutoControlTransportCN + "truckWeightBill";//生成磅单接口
        private static readonly string EndYxInfoAN = AutoControlTransportCN + "endYxInfo";//结束运销流程
        private static readonly string GetSendTypeByCardNoAN = AutoControlTransportCN + "getSendTypeByCardNo";//通过卡号判断采购销售
        private static readonly string AutoIntoExitAN = AutoControlTransportCN + "autoIntoExit";//自动出入厂
        private static readonly string JudgeTruckNoAN = AutoControlTransportCN + "judgeTruckNo";//扫到车牌判断接口

        private static readonly string WeighbridgeCN = "weighbridge/";
        private static readonly string ListWeighbridgeAN = WeighbridgeCN + "listWeighbridge";//地磅信息列表

        /// <summary>
        /// 扫到车牌判断接口
        /// </summary>
        /// <param name="truckNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> JudgeTruckNo(string truckNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("truckNo", truckNo);
            string ret;
            string url = InterfaceExecute.GetUrl(JudgeTruckNoAN, keyValuePairs);
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("AutoIntoExit " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);
        }


        /// <summary>
        /// 自动出入厂
        /// </summary>
        /// <param name="wareName"></param>
        /// <param name="wareState"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> AutoIntoExit(AutoIntoExitSendM autoIntoExitSendM)
        {
            string ret;
            string url = InterfaceExecute.GetUrl(AutoIntoExitAN);
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(autoIntoExitSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("AutoIntoExit " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }

        /// <summary>
        /// 根据硬件名称修改硬件状态
        /// </summary>
        /// <param name="wareName"></param>
        /// <param name="wareState"></param>
        /// <param name="remark"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> UpdateHardWareByName(string wareName, int wareState, string remark)
        {
            string ret;
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("wareName", wareName);
            keyValuePairs.Add("wareState", wareState.ToString());
            keyValuePairs.Add("remark", remark);
            string url = InterfaceExecute.GetUrl(UpdateHardWareByNameAN, keyValuePairs);
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("UpdateHardWareByName " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 地磅信息列表
        /// </summary>
        /// <param name="listWeighbridgeSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<List<ListWeighbridgeReceiveM>> ListWeighbridge(ListWeighbridgeSendM listWeighbridgeSendM)
        {
            string url = InterfaceExecute.GetUrl(ListWeighbridgeAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(listWeighbridgeSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("ListWeighbridge " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<List<ListWeighbridgeReceiveM>>>(ret);

        }
        /// <summary>
        /// 通过卡号判断采购销售
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> GetSendTypeByCardNo(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(GetSendTypeByCardNoAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetSendTypeByCardNo " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 结束运销流程
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> EndYxInfo(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(EndYxInfoAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("EndYxInfo " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 生成磅单接口
        /// </summary>
        /// <param name="weightBillDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckWeightBill(Models.WeightBillDtoSendM weightBillDtoSendM)
        {
            string url = InterfaceExecute.GetUrl(TruckWeightBillAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(weightBillDtoSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckWeightBill " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 车辆称重接口
        /// </summary>
        /// <param name="weightDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckWeigh(WeightDtoSendM weightDtoSendM)
        {
            string data = Newtonsoft.Json.JsonConvert.SerializeObject(weightDtoSendM);
            Common.Log4.LogManage.WriteInfo("TruckWeigh:" + data);
            string url = InterfaceExecute.GetUrl(TruckWeighAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, data);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckWeigh " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 车辆卸车接口
        /// </summary>
        /// <param name="unloadingDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckUnloading(UnloadingDtoSendM unloadingDtoSendM)
        {
            string url = InterfaceExecute.GetUrl(TruckUnloadingAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(unloadingDtoSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckUnloading " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 车辆除皮接口
        /// </summary>
        /// <param name="tareDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckTare(TareDtoSendM tareDtoSendM)
        {
            string data = Newtonsoft.Json.JsonConvert.SerializeObject(tareDtoSendM);
            Common.Log4.LogManage.WriteInfo("TruckTare:" + Newtonsoft.Json.JsonConvert.SerializeObject(tareDtoSendM));
            string url = InterfaceExecute.GetUrl(TruckTareAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, data);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckTare " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 车辆出场接口
        /// </summary>
        /// <param name="exitDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckExit(ExitDtoSendM exitDtoSendM)
        {
            string url = InterfaceExecute.GetUrl(TruckExitAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(exitDtoSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckExit " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 车辆入场接口
        /// </summary>
        /// <param name="admissionDtoSendM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<int?> TruckAdmission(AdmissionDtoSendM admissionDtoSendM)
        {
            string url = InterfaceExecute.GetUrl(TruckAdmissionAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(admissionDtoSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckAdmission " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<int?>>(ret);

        }
        /// <summary>
        /// 获取磅单信息接口
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<Models.YxYsTransportReturnDto> GetTruckYxInfo(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(GetTruckYxInfoAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("TruckAdmission " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<Models.YxYsTransportReturnDto>>(ret);

        }
        /// <summary>
        /// 获取最后磅单信息接口
        /// </summary>
        /// <param name="cardNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<Models.YxYsTransportReturnDto> GetTheLatest(string cardNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("cardNo", cardNo);
            string url = InterfaceExecute.GetUrl(GetTheLatestAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetTheLatest " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<Models.YxYsTransportReturnDto>>(ret);

        }
        /// <summary>
        /// 当前车辆是否为黑名单
        /// </summary>
        /// <param name="truckNo"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<bool> GetBlack(string truckNo)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("truckNo", truckNo);
            string url = InterfaceExecute.GetUrl(GetBlackAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetBlack " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<bool>>(ret);

        }
        /// <summary>
        /// 设备删除接口
        /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<string> DelHardWareById(string hid)
        {
            string url = InterfaceExecute.GetUrl(DelHardWareByIdAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, hid);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("DelHardWareById " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<string>>(ret);

        }
        /// <summary>
        /// 设备监控列表查询
        /// </summary>
        /// <param name="getHardWareSSendM"></param>
        /// <returns></returns>
        public static GetHardWareSRceiveM GetHardWareS(GetHardWareSSendM getHardWareSSendM)
        {
            Dictionary<string, string> data = new Dictionary<string, string>();
            string url = InterfaceExecute.GetUrl(GetHardWareSAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(getHardWareSSendM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetHardWareS " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<GetHardWareSRceiveM>(ret);

        }
        /// <summary>
        /// 设备监控新增接口
        /// </summary>
        /// <param name="hardWareM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<string> AddHardWare(HardWareM hardWareM)
        {
            string url = InterfaceExecute.GetUrl(AddHardWareAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(hardWareM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("AddHardWare " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<string>>(ret);
        }
        /// <summary>
        /// 设备监控列更新接口
        /// </summary>
        /// <param name="hardWareM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<string> UpdateHardWareByid(HardWareM hardWareM)
        {
            string url = InterfaceExecute.GetUrl(UpdateHardWareByidAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url, Newtonsoft.Json.JsonConvert.SerializeObject(hardWareM));
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("UpdateHardWareByid " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<string>>(ret);

        }
        /// <summary>
        /// 设备监控详情
        /// </summary>
        /// <param name="hid"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<HardWareM> GetHardWareById(string hid)
        {
            Dictionary<string, string> keyValuePairs = new Dictionary<string, string>();
            keyValuePairs.Add("hid", hid);
            string url = InterfaceExecute.GetUrl(GetHardWareByIdAN, keyValuePairs);
            string ret;
            try
            {
                ret = HttpClientUtil.doGetMethodToString(url);
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("GetHardWareById" + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<HardWareM>>(ret);

        }
        /// <summary>
        /// 登录
        /// </summary>
        /// <param name="loginUserM"></param>
        /// <returns></returns>
        public static Models.ReceiveDataBase<LoginReceiveM> Login(LoginUserM loginUserM)
        {
            string url = InterfaceExecute.GetUrl(LoginAN);
            string ret;
            try
            {
                ret = HttpClientUtil.doPostMethodToString(url,
                    Newtonsoft.Json.JsonConvert.SerializeObject(loginUserM)
                    );
            }
            catch (Exception ex)
            {
                Common.Log4.LogManage.WriteErr("Login " + ex.ToString());
                return null;
            }
            return Newtonsoft.Json.JsonConvert.DeserializeObject<Models.ReceiveDataBase<LoginReceiveM>>(ret);

        }

    }
}
